package org.example.factoryBean;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class ServiceFactoryBean implements FactoryBean<Service> {

    @Value("${service.type}")
    private String type;

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public Service getObject() throws Exception {
        if ("service1".equals(type)) {
            return new ServiceImpl1();
        } else if ("service2".equals(type)) {
            return new ServiceImpl2();
        }
        return null;
    }

    @Override
    public Class<?> getObjectType() {
        return Service.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
